from sklearn import datasets
from sklearn.model_selection import train_test_split
import torch
import torch.nn as nn
from torch.autograd import Variable
import torchvision.datasets as dsets

data = datasets.load_breast_cancer()
x = data['data']
y = data['target']
print(x.shape)
y = y.reshape([569,1])
print(y.shape)

train_x,test_x,train_y,test_y = train_test_split(x,y,train_size=0.75)
train_X = Variable(torch.Tensor(train_x))
train_Y = Variable(torch.Tensor(train_y))
test_X = Variable(torch.Tensor(test_x))
test_Y = Variable(torch.Tensor(test_y))

model = nn.Linear(30,1,bias=True)
sigmoid = nn.Sigmoid()
model = nn.Sequential(model,sigmoid)

losses = nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(),lr=0.01)

for i in range(10001):
    optimizer.zero_grad()
    h = model(train_X)
    loss = losses(h,train_Y)
    loss.backward()
    optimizer.step()
    if i%100==0:
        print(i,loss.data.numpy())